/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import dao.Deal_DAO;
import dao.user_DAO;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dao.user_DAO;
import java.util.ArrayList;
import javax.servlet.http.HttpSession;
import pojo.User;

/**
 *
 * @author Administrator
 */
public class xl_Login extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
           
            String username = request.getParameter("email");
            String pass = request.getParameter("psw");
             HttpSession session = request.getSession();
            if (user_DAO.KiemTraTrungLap2(username,pass) == -1) {
               User nguoiDung = user_DAO.layThongTinUser(username);
               request.setAttribute("DaDangNhap",nguoiDung);
               out.print(1);
                out.println("                    <a href='' class='aImgLogin'><img src='"+nguoiDung.getHinhDaiDien()+"' width='58px' height='58px'></a>");
                out.println("            	   <p class='styleText7'>Xin Chào</p>");
                out.println("            	   <p class='styleText15 pNameMem'>"+nguoiDung.getTenDangNhap()+"</p>");
                out.println("            	   <p class='styleText7'><a class='colorPF' href='xl_viewProfile?Action=view&ID="+nguoiDung.getId()+"'>Profile</a></p>");
                session.setAttribute("DaDangNhap",nguoiDung);
            }else{
                out.println("  <ul class='inner_SinginNew'>");
                out.println("                                <li>");
                out.println("                                    <p class='styleText7 pPopSI'>Ký Danh:</p>");
                out.println("                                    <div class='div_txtNew'>");
                out.println("                                        <div class='txt_tlNew'></div>");
                out.println("                                        <div class='txt_ctNew'></div>");
                out.println("                                        <div class='txt_trNew'></div>");
                out.println("                                        <div class='txt_clNew'>");
                out.println("                                            <div class='txt_crNew'>");
                out.println("                                                <div class='txt_inner_New'>");
                out.println("                                                    <input autocomplete='off' id='emailLogin' name='emailLogin' type='text'>");
                out.println("                                                </div>");
                out.println("                                            </div>");
                out.println("                                        </div>");
                out.println("                                        <div class='txt_blNew'></div>");
                out.println("                                        <div class='txt_cbNew'></div>");
                out.println("                                        <div class='txt_brNew'></div>");
                out.println("");
                out.println("                                    </div>");
                out.println("                                </li>");
                out.println("                                <li class='li_PassSinginNew'>");
                out.println("                                    <p class='styleText7 pPopSI'>Mật Khẩu:</p>");
                out.println("                                    <div class='div_txtNew'>");
                out.println("                                        <div class='txt_tlNew'></div>");
                out.println("                                        <div class='txt_ctNew'></div>");
                out.println("                                        <div class='txt_trNew'></div>");
                out.println("                                        <div class='txt_clNew'>");
                out.println("                                            <div class='txt_crNew'>");
                out.println("                                                <div class='txt_inner_New'>");
                out.println("                                                    <input id='pswLogin' value='' name='pswLogin' type='password'>");
                out.println("                                                </div>");
                out.println("                                            </div>");
                out.println("                                        </div>");
                out.println("                                        <div class='txt_blNew'></div>");
                out.println("                                        <div class='txt_cbNew'></div>");
                out.println("                                        <div class='txt_brNew'></div>");
                out.println("");
                out.println("                                    </div>");
                out.println("                                </li>");
                out.println("                            </ul>");
                out.println("                        ");
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
